<template>
	<view class="notice-detail">
		<view class="banner" v-if="detail.cover">
			<image class="banner-img" :src="detail.cover"></image>
			<view class="banner-title in2line">{{ detail.title }}</view>
		</view>
		<view class="banner-title" v-if="!detail.cover">
			{{detail.title}}</view>
		<view class="article-meta" v-if="detail.created_at">
			<text class="article-text">发布于</text>
			<text class="article-time">{{ detail.created_at || detail.time }}</text>
		</view>
		<view class="article-content">
			<jyf-parser :html="detail.content" ref="article" :lazy-load="true" :selectable="true" @imgtap="previewImage"></jyf-parser>
		</view>
	</view>
</template>

<script>
	import jyfParser from "@/components/jyf-parser/jyf-parser";
	export default {
		components: {
			jyfParser
		},
		data() {
			return {
				detail: {},
				id: undefined,
			};
		},
		onLoad(option) {
			this.id = option.id;
			this.getDetail();
		},
		onShareAppMessage() {
			return {
				title: this.banner.title,
				path: `/pages/article/detail?id=${this.id}`
			};
		},
		methods: {
			getDetail() {
				this.$http.get('api/default/article', {
					params: {
						id: this.id
					}
				}).then((res) => {
					if (res.created_at) {
						res.created_at = this.$config.timeFormat(res.created_at, 'yyyy-mm-dd hh:MM:ss')
					}
					this.detail = res;
					uni.setNavigationBarTitle({
						title: res.title
					});
				}).catch((err) => {

				});
			},
			previewImage(e) {
				uni.previewImage({
					current: 0,
					urls: e.src
				});
			}
		}
	};
</script>

<style lang="scss">
	.notice-detail {
		.banner {
			overflow: hidden;
			position: relative;
			background-color: #f8f8f8;

			.banner-img {
				height: 300upx;
				width: 100%;
			}

			.banner-title {
				max-height: 84upx;
				overflow: hidden;
				position: absolute;
				bottom: 0;
				width: 100%;
				font-size: 30upx;
				font-weight: 400;
				line-height: 42upx;
				color: white;
				z-index: 11;
				background-color: rgba(0, 0, 0, 0.25);
				padding: 4upx 20upx;
			}
		}

		.banner-title {
			padding: 30rpx 30rpx 0;
			font-size: 21rpx;
		}

		.article-meta {
			padding: 20upx 30upx;
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			color: gray;

			.article-text,
			.article-time{
				font-size: 20upx;
				line-height: 50upx;
			}
			
			.article-time {
				margin-left: 20rpx;
			}
		}

		.article-content {
			padding: 0 30upx;
			overflow: hidden;
			font-size: 30upx;
			margin-bottom: 30upx;
		}
	}
	.in2line {
		display: -webkit-box !important;
		overflow: hidden;
		text-overflow: ellipsis;
		word-break: break-all;
		-webkit-box-orient: vertical !important;
		-webkit-line-clamp: 2;
	}
</style>
